/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cifar10.featureextraction;

import de.lmu.ifi.dbs.jfeaturelib.LibProperties;
import de.lmu.ifi.dbs.jfeaturelib.features.Histogram;
import ij.process.ColorProcessor;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;

/**
 *
 * @author mwh
 */
public class HistogramWrapper extends AbstractFixedSizeFeatureExractor {

    public enum Type {

        RED, GREEN, BLUE, GRAY
    }

    LibProperties lp;

    public HistogramWrapper(int bins, Type type) {
        name = "Histogram" + type.name();
        size = bins;
        lp = new LibProperties();
        lp.setProperty(LibProperties.HISTOGRAMS_BINS, "10");
        String prefix = "H" + type.name();
        switch (type) {
            case RED:
                lp.setProperty(LibProperties.HISTOGRAMS_TYPE, Histogram.TYPE.Red.name());
                break;
            case BLUE:
                lp.setProperty(LibProperties.HISTOGRAMS_TYPE, Histogram.TYPE.Blue.name());
                break;
            case GREEN:
                lp.setProperty(LibProperties.HISTOGRAMS_TYPE, Histogram.TYPE.Green.name());
                break;
            case GRAY:
                lp.setProperty(LibProperties.HISTOGRAMS_TYPE, Histogram.TYPE.Gray.name());
                break;
            default:
                lp.setProperty(LibProperties.HISTOGRAMS_TYPE, Histogram.TYPE.RGB.name());
        }
        featuresNames = new String[size];
        for (int i = 1; i <= size; i++) {
            featuresNames[i-1] = prefix + "i";
        }
    }

    @Override
    public double[] getValues(BufferedImage image) {
        Histogram fd = new Histogram();
        fd.setProperties(lp);
        ColorProcessor cp = new ColorProcessor(image);
        fd.run(cp);
        double[] feats = fd.getFeatures().get(0);
        return feats;
    }

}
